var aAllFormFilters=new Array();
	var aAllNamesAndValues=new Array();
	function fCreateFilterSelector(sSelectedName,sSelectedValue,sSelectedOperator){		
		var bFirstFilter=new Boolean(true);	
		var i=aAllFormFilters.length;
		
		var oTemplate=document.getElementById('template');	
		var oWorkArea=document.getElementById('filter');	
		
		var oNewNode=oTemplate.cloneNode(true);		
		var oSelects=oNewNode.getElementsByTagName('SELECT');	
		
		var oSelField=oSelects[1];
		var oSelValue=oSelects[2]
		var oSelOper=oSelects[0];	
		
		if (aAllFormFilters.join('')=='')bFirstFilter=true;
		else bFirstFilter=false;
		
		oSelField.setAttribute('name','form_filter['+i+'][field]');			
		oSelValue.setAttribute('name','form_filter['+i+'][value]');	
		oSelOper.setAttribute('name','form_filter['+i+'][operator]');		
		
		oSelField.setAttribute('id','filter_select_field_'+i);					
		oSelValue.setAttribute('id','filter_select_value_'+i);		
		oSelOper.setAttribute('id','filter_operator_'+i);		
		oNewNode.setAttribute('id','filter_filter_'+i);
					
		oNewNode.style.visibility='visible';
		oNewNode.style.position='relative';			
		
		fSetSelectedByValue (oSelField,sSelectedName);
		fPopulateValueSelector(oSelField,oSelValue,oSelOper)
		fSetSelectedByValue (oSelOper,sSelectedOperator);
		
		aAllFormFilters[i]=new Array();		
		aAllFormFilters[i][0]=oNewNode.id;
		aAllFormFilters[i][1]=oSelField.id;	
		aAllFormFilters[i][2]=oSelValue.id;	
		aAllFormFilters[i][3]=oSelOper.id;	
		
		//if (bFirstFilter==true) oSelOper.style.visibility="hidden";		
		
		oWorkArea.appendChild(oNewNode);
		
		oNoFilterMessage.style.visibility="hidden";
		oNoFilterMessage.style.position="absolute";					
	}
	function fSetSelectedByValue (oSelect,sValue){		
		for (i=0; i<oSelect.options.length; i++){					
			if (oSelect.options[i].getAttribute('value')==sValue) oSelect.selectedIndex=i;
		}		
	}
	function fDeleteFilterSelector (oSelf, oGrandParent){		
		var nID=oGrandParent.id.substr(14);		
		aAllFormFilters[nID]=null;		
		oGrandParent.parentNode.removeChild(oGrandParent);	
		
		if (aAllFormFilters.join('')=='')	{
			oNoFilterMessage.style.visibility="visible";
			oNoFilterMessage.style.position="relative";		
		}
	}
	function fDeleteAllFilters () {
		for(i=0; i<aAllFormFilters.length; i++){
			if (aAllFormFilters[i]!=null) {
				fDeleteFilterSelector('',document.getElementById(aAllFormFilters[i][0]));
			}
		}			
	}
	function fRegisterFormFields(sName,sValue){
		var i=aAllNamesAndValues.length
		aAllNamesAndValues[i]=new Array();
		aAllNamesAndValues[i][0]=sName;
		aAllNamesAndValues[i][1]=sValue;
	}
	function fPopulateValueSelector(oSelf,oChild,oOperator){
		var sFieldName=oSelf.value;
		var nOptCounter=new Number(0);
		
		fRemoveAllSelectOptions(oChild);
		if (sFieldName=='') {
			oChild.disabled=true;
			oOperator.disabled=true;
		} else {
			oChild.disabled=false;
			oOperator.disabled=false;
		}
		
		for(i=0; i<aAllNamesAndValues.length; i++){			
			if(aAllNamesAndValues[i][0]==sFieldName){
				oChild.options[nOptCounter]=new Option(aAllNamesAndValues[i][1],aAllNamesAndValues[i][1], false, false);
				nOptCounter++;		
			}	
		}		
	}
	function fRemoveAllSelectOptions(oSelect){
		for (i=(oSelect.options.length-1); i>=0; i--) {
			oSelect.options[i]=null;
		}		
	}